import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import '../../models/home_tabs_model.dart';
import '../../utils/http_util.dart';

class HomeViewModel extends GetxController {
  var titleIndex = 0.obs;
  var tabs = [].obs;
  var msgCount = 0.obs;

  changeIndex(int index) {
    titleIndex.value = index;
  }

  Future<void> queryTabs() async {
    EasyLoading.show(status: 'loading', maskType: EasyLoadingMaskType.clear);
    try {
      final result = await HttpUtil().get('drama/type');
      final dynamic responseData = result.data['data']; // 明确类型声明
      tabs.value = HomeTabsModel.fromJson(responseData).dictionary;
    } catch (e) {
      EasyLoading.showToast('请求失败');
    }
    EasyLoading.dismiss();
  }

  Future<void> queryMsgCount() async {
    try {
      final result = await HttpUtil().get('member/message/total');
      final dynamic responseData = result.data['data']; // 明确类型声明
      msgCount.value = responseData['count'];
    } catch (e) {
      EasyLoading.showToast('请求失败');
    }
  }
}
